package org.midi.j2me.util;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Image;

public class Util {

	public static byte[] getDataFromRes(String fileName) {
		byte[] buf = null;

		InputStream is = null;
		try {
			is = new Object().getClass().getResourceAsStream("/MixImage_1.dat");
			int len=is.available();
			int offset = 0;
			
		} catch (Exception e) {
			System.out.println(e);
		} finally {
			try {
				if (is != null)
					is.close();
			} catch (Exception e) {
			}
		}
		return buf;
	}

	public static Image getImageFromRes(String name) {
		Image img = null;
		try {
			img = Image.createImage(name);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		return img;
	}

	public static Image getImageFromSD(String name) {
		Image img = null;
		FileConnection fc = null;
		try {
			fc = (FileConnection) Connector.open(name);
			img = Image.createImage(fc.openInputStream());
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		return img;
	}

}
